﻿#include "BoardController.h"

#include "windows.h"

#include <boost/bind.hpp>


using namespace Controllers;

BoardController::BoardController(Views::IBoardView* view, Utils::Logging::ILogger* logger,
	Players::Player* player, Cards::RoomsCards rooms_cards)
	: view(view), player(player), rooms_cards(rooms_cards)
{
	this->logger = logger;
	connectEvent<void (BoardItems::Room*)>(view->playerRoomChangeEvent,
		boost::bind(&BoardController::setPlayerPosition, this, _1));
}

void BoardController::perform()
{
	view->askForPlayerNewPosition(player, rooms_cards);
}

void BoardController::setPlayerPosition(BoardItems::Room* room)
{
	player->piece->room = room;
	for (Cards::RoomsCards::iterator i = rooms_cards.begin(); i != rooms_cards.end(); ++i)
	{
		if ((*i)->room == room)
		{
			logger->boardRoomChange(*i);
			break;
		}
	}
	movePerformedEvent();
}

void BoardController::moveToRoom(Players::Player* player, BoardItems::WeaponPiece* weapon, BoardItems::Room* room)
{
	player->piece->room = room;
	weapon->room = room;
}

